const UserModel = require("../model/UserModel");

// 查找数据库匹配用户
const UserService = {
    find: (userInfo, pages = { limit: 1, size: 10 }) => {
        const { limit, size } = pages
        return UserModel.find(Object.assign(userInfo), ["username", "status", "telephone", "email", "idnumber", "roles", "menus", "department", "post", "avatar", "createTime", "nickname", "sort"]).skip((limit - 1) * size).limit(size).sort({ sort: -1 })
    },
    append: (userInfo) => {
        return UserModel.create(userInfo)
    },
    update: (userInfo) => {
        return UserModel.updateOne({ _id: userInfo._id }, userInfo)
    },
    remove: (id) => {
        return UserModel.deleteOne({ _id: id })
    },

}
module.exports = UserService